import 'dart:io';
///引入共享头部
import '../../../common/shard.dart';

import '../../../widget/cropper_image.dart';

class CropperImagePage extends StatefulWidget {
	const CropperImagePage({Key? key}) : super(key: key);

	@override
	State<CropperImagePage> createState() => _CropperImagePageState();
}

class _CropperImagePageState extends State<CropperImagePage> {

	String origin="http://c-ssl.duitang.com/uploads/item/201808/21/20180821223915_yyrpi.thumb.400_0.jpg";
	String? cropper;

	@override
	Widget build(BuildContext context) {
		return CustomCupertinoScaffold(
			titleText: "图片裁剪",
			navBackgroundColor: Theme.of(context).primaryColor,
			body: Column(
				children:  [
					const SizedBox(height:50),
					const Text("未裁剪图片"),
					SizedBox(
						child: CacheImage(url: origin),
						width: 300,
						height: 300,
					),
					TextButton(
						onPressed: () async {
							File? cropperFile=await Get.to(()=>CropperImage(image:origin));
							if(cropperFile!=null){
								setState(() {
									cropper=cropperFile.path;
								});
							}
						},
						child: const Text("开始裁剪")
					),
					const SizedBox(height:50),
					const Text("裁剪结果"),
					if(cropper!=null)
					SizedBox(
						child: CacheImage(url: cropper!),
						width: 300,
						height: 300,
					)
				],
			),
		);
	}
}
